// pages/my/my.js
import Https from "../../utils/api.js"
const http = new Https
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		time:"1",
		animationData: {},
		isShow: [0, 0, 0],
		list:[
      {
        "pagePath": "/pages/home/home",
        "text": "首页",
        "iconPath": "/assets/tabbar/home_new.png",
        "selectedIconPath": "/assets/tabbar/home_new_.png",
        "selectedColor": "#3fbaa6"
      },
      {
        "pagePath": "/pages/chatList/chatList",
        "text": "消息",
        "iconPath": "/assets/tabbar/home_message.png",
        "selectedIconPath": "/assets/tabbar/home_message.png",
        "selectedColor": "#3fbaa6"
      },
      {
        "pagePath": "/pages/publish/publish",
        "text": "发布",
        "iconPath": "/assets/tabbar/mine_new.png",
        "selectedIconPath": "/assets/tabbar/mine_new_.png",
        "selectedColor": "#3fbaa6"
      },
      {
        "pagePath": "/pages/my/my",
        "text": "我的",
        "iconPath": "/assets/tabbar/news_new.png",
        "selectedIconPath": "/assets/tabbar/news_new_.png",
        "selectedColor": "#3fbaa6"
      }
    ],
		userInfo:{
			nick_name:"点击获取信息",
			avatar:"../../assets/home/Headportrait/s01.png",
		},
		isUser:false
	},
	rotate() {
		var animation = wx.createAnimation({
			duration: 1000,
			timingFunction: "ease"
		});
		this.animation = animation
		animation.rotate(760).step()
		this.setData({
			animationData: animation.export()
		});
		wx.showToast({
			title: "更新成功",
			icon: "none"
		})
		setTimeout(() => {
			animation.rotate(0).step()
			this.setData({
				animationData: animation.export()
			})
		}, 1200)
	},
	question() {
		wx.navigateTo({
			url: '/pages/my/location_check_in/location_check_in'
		})
	},
	attention() {
		wx.navigateTo({
			url: 'attention/attention'
		})
	},
	release() {
		wx.navigateTo({
			url: 'release/release'
		})
	},
	buy(){
		wx.navigateTo({
			url:"/pages/publish/buy/buy"
		})
	},
	consume() {
		wx.navigateTo({
			url:"/pages/my/consumeList/consumeList"
		})
	},

	getUserProfile(){
		console.log(1)
		let that = this
		if(wx.getStorageSync('hasUserInfo') == true){
			return;
		}
		wx.getUserProfile({
      desc: '授权登录', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
				console.log(res.userInfo)
				http.request("wx/userInfo",{
					nick_name:res.userInfo.nickName,
						sex: res.userInfo.gender == 1 ? '男' : '女',
						avatar: res.userInfo.avatarUrl,
				},"POST").then((res)=>{
					console.log(res)
					if(res.code == 200){
						wx.showToast({
							title: '获取成功',
							icon:"none"
						})
						that.setData({
							userInfo:res.data,
							hasUserInfo: true,
							isUser:true
						})
						wx.setStorageSync('userInfo', res.data)
						wx.setStorageSync('hasUserInfo', true)
					}else{
						wx.showToast({
							title: '用户信息获取失败',
							icon:"none"
						})
					}
				})
      }
    })
	},
	goto() {
		wx.navigateTo({
			url: "pages/home/homeWYue/homeWYue"
		})
	},
	phone() {
		wx.makePhoneCall({
			phoneNumber: "10086",
		})
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	calculate() {
		wx.navigateTo({
			url: "calculate/calculate"
		})
	},
	AboutUs() {
		wx.navigateTo({
			url: 'AboutUs/AboutUs'
		})
	},
	agreement() {
		wx.navigateTo({
			url: 'agreement/agreement'
		})

	},
	onShow: function() {

	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {
		if(wx.getStorageSync('hasUserInfo') == true){
			this.setData({
				userInfo:wx.getStorageSync('userInfo')
			})
		}
	},

	layout(){
		let that = this
		wx.showModal({
			title: '确定退出么？',
			content: '这是一个模态弹窗',
			success (res) {
				if (res.confirm) {
					wx.removeStorageSync('hasUserInfo')
					let userInfo = {
						nick_name:"点击获取信息",
						avatar:"../../assets/home/Headportrait/s01.png",
					}
					that.setData({isUser:false,userInfo:userInfo})
					that.onShow()
				} else if (res.cancel) {
					
				}
			}
		})
	},


	/**
	 * 生命周期函数--监听页面隐藏
	 */ 
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
